package dao;

import common.Course;
import common.Select;
import common.User;
import service.ControlSCConnectionThread;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

public class GetSelectTask {
    private static Connection conn=DataBaseConnect.getConn();
    private static String sql="select id,name,courseid from selecttask where courseid=?";
    private static PreparedStatement pstmt;
    static {
        try {
            pstmt=conn.prepareStatement(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public static Vector<Select> gatSelectTask(String courseid){
        Vector<Select> selectTask=new Vector<>();
        try {
            pstmt.setString(1,courseid);
            ResultSet rs=pstmt.executeQuery();
            while (rs.next()){
                Vector<User> selected=GetSelected.getSelected(rs.getString(1));
                Select add=new Select(rs.getString(1),rs.getString(3),rs.getString(2),selected);
                selectTask.add(add);
            }
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("获取我教的课失败");
        }
        return selectTask;
    }
}
